<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <div th:insert="commen/head :: header">
    </div>
</head>
<body style="background-color: rgb(242,244,247)">
<div th:insert="commen/navigationBar :: topNavBar"></div>
    <div class="container" style="background-color: #fff; margin-top: 5px; border-radius: 5px">
        <div class="row">
            <div class="col-md-12">
                <div  style="float:left;">
                    <span style="font-size: 36px; font-weight: bold;" th:text="${topic.getTopicTitle()}"></span>
                </div>
                <div style="float:right;">
                    <a style="margin-top: 8px;" class="btn btn-primary" href="#section1">回复</a>
                </div>
            </div>
            <hr>
            <hr>
            <div class="col-md-12">
                <img  style="width: 40px; height: 40px; border-radius: 20px" th:src="${'../img/' + topic.getUser().getUserImg()}" alt="">
                <span style="font-size: 18px; font-weight: bold;" th:text="${topic.getUser().getUserName()}"></span>
                <span style="color:#8c8c8c; font-size: 12px" th:text="${topic.getTopicTime()}"></span>
            </div>

            <div class="col-md-12" style="margin-top: 10px; margin-left: 42px;">
                <p style="font-size: 18px" th:text="${topic.getTopicContent()}"></p>
            </div>
        </div>

    </div>
    <div class="container" style="background-color: #fff; margin-top: 5px; border-radius: 5px">
        <div class="row">
            <div class="col-md-12">
                <div class="text-center" th:if="${replies == null}">
                    <p>暂无回复</p>
                </div>
                <div th:if="${replies != null}">
                    <div th:each="replie : ${replies}" style="padding: 10px;">
                        <div style="float: right">
                            <button th:onclick="replyModel([[${replie.getReplyId()}]], [[${replie.getUserId()}]], [[${replie.getTopicId()}]])" class="btn btn-primary" data-toggle="modal" data-target="#reply" role="button">回复</button>
                        </div>
                        <div>
                            <img th:src="${'../img/' + replie.getUser().getUserImg()}" alt="" style="width: 40px; height: 40px; border-radius: 20px">
                            <span style="font-size: 18px; font-weight: bold; " th:text="${replie.getUser().getUserName()}"></span><br>
                            <span style="margin-left: 42px;color:#8c8c8c; font-size: 12px" th:text="${replie.getReplyTime()}"></span>
                            <p style="margin-left: 42px; font-size: 18px" th:text="${replie.getReplyContent()}"></p>
                        </div>
                        <div th:if="${replyed != null}"  style="background-color: #fafafa; margin-left: 42px; border-radius: 15px; padding: 15px;">
                            <div th:each="beReply : ${replyed}">
                                <div  th:if="${replie.getReplyId() == beReply.getReplyedId()}">
                                    <span style="font-size: 18px" th:text="${beReply.getUser().getUserName()}"></span> 回复 <span style="font-size: 18px" th:text="${beReply.getBeReplyedUserName()}"></span><br>
                                    <span style="color:#8c8c8c; font-size: 12px"  th:text="${beReply.getReplyTime()}"></span>
                                    <p>[[${beReply.getReplyContent()}]]</p>
                                    <button style="margin-left: 95%;" th:onclick="replyModel([[${replie.getReplyId()}]], [[${beReply.getUserId()}]], [[${beReply.getTopicId()}]])" class="btn" data-toggle="modal" data-target="#reply" role="button">回复</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container" style="background-color: #fff; margin-top: 10px;margin-bottom: 10px;padding-bottom: 10px; border-radius: 5px">
        <div class="row">
            <div class="col-md-12">
                <h4>回复话题</h4>
                <form th:action="@{/addReply}" method="post">
                    <input type="hidden" th:value="${topicId}" name="topicId">
                    <p><textarea name="replyContent" class="form-control" rows="5" placeholder="回复话题"></textarea></p>
                    <input class="btn btn-primary" type="submit" value="回复">
                </form>
            </div>
        </div>
    </div>

    <!--回复模态框-->
    <div class="modal fade" id="reply">
        <div class="modal-dialog">
            <div class="modal-content">
                <!-- 模态框头部 -->
                <div class="modal-header">
                    <h4 class="modal-title">回复</h4>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                <!-- 模态框主体 -->
                <div class="modal-body">
                    <form th:action="@{/replyUser}" method="post">
                        <input type="hidden" id="rId" name="replyedId">
                        <p><textarea name="replyContent" class="form-control" rows="3" placeholder="回复话题"></textarea></p>
                        <input type="hidden" id="uId" name="userId">
                        <input type="hidden" id="tId" name="topicId">
                        <input class="btn btn-success" type="submit" value="回复">
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script>
        let replyIdm = document.getElementById("rId");
        let userIdm = document.getElementById("uId");
        let topicIdm = document.getElementById("tId");
        function replyModel(replyId, userId, topicId) {
            replyIdm.value = replyId;
            userIdm.value = userId;
            topicIdm.value = topicId;
        }
    </script>
</body>
</html>